#include "new_printf.h"





s32 new_printf(s32 level, s8 *filename, const s8 *format, ...)
{

    if(level <= StepLevel)
    {
        s32 result;
        s8 buf[512];
        va_list vp;

        va_start(vp, format);
        result = vsprintf(buf, format, vp);
        va_end(vp);

        printf("%s", buf);

        if(filename != NULL)
        {
            s32 fd = open(filename, O_WRONLY|O_CREAT|O_APPEND, 0664);
            if(fd < 0)
            {
                perror("open err");
                return -1;
            }

            if(write(fd, buf, strlen(buf)) < 0)
            {
                perror("write err");
                return -1;
            }

            close(fd);

        }
        return result;
    }



}
